package com.jinke.uang.ui.activity.mine;

import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jinke.uang.R;
import com.jinke.uang.base.BaseNormalActivity;
import com.jinke.uang.base.BaseResponse;
import com.jinke.uang.common.RouterMap;
import com.jinke.uang.bean.RealNameInfoData;
import com.jinke.uang.constant.HttpConstant;
import com.jinke.uang.model.MineModule;
import com.jinke.uang.presenter.CommonPresenter;
import com.jinke.uang.utils.MaskUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 个人中心的页面  显示实名认证信息界面
 */
@Route(name = "个人信息", path = RouterMap.MINE_PERSONAL_INFO)
public class PersonalDetailsActivity extends BaseNormalActivity <CommonPresenter,MineModule> {

    @BindView(R.id.personal_user_name)
    TextView personal_user_name;
    @BindView(R.id.personal_id_card_num)
    TextView personal_id_card_num;
    @BindView(R.id.personal_user_phone_num)
    TextView personal_user_phone_num;

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void onUIReady() {

        showLoadingView();
        mPresenter.getData(HttpConstant.REAL_NAME_AUTH_INFO,null);
    }

    @Override
    protected int getContentResId() {
        return R.layout.activity_personal_details;
    }

    @Override
    public String getPageTitle() {
        return getStringResource(R.string.personal_detail_page_title);
    }

    @Override
    protected CommonPresenter getPresenter() {
        return new CommonPresenter();
    }

    @Override
    protected MineModule getModule() {
        return new MineModule();
    }

    @Override
    public void showResponse(int apiType, String listType,Object o) {
        if(apiType== HttpConstant.REAL_NAME_AUTH_INFO){// 展示实名认证信息
            dismissLoadingView();
            BaseResponse<RealNameInfoData> realNameInfoResponse = (BaseResponse<RealNameInfoData>) o;
            fillDetails(realNameInfoResponse.getData());
        }
    }

    private void fillDetails(RealNameInfoData data) {
        if (personal_user_name != null) {
            MaskUtils.setText(personal_user_name, data.getRealName());
        }

        if (personal_id_card_num != null) {
            MaskUtils.setText(personal_id_card_num, data.getCardNo());
        }

        if (personal_user_phone_num != null) {
            MaskUtils.setText(personal_user_phone_num, data.getUserName());
        }
    }

    @Override
    public void showError(Throwable e) {
        dismissLoadingView();
    }
}
